<html>
<head>
    <meta charset="UTF-8">
    <title>修改</title>
</head>
<link rel="stylesheet" href="/static/layui/css/layui.css"/>
<body>
<form class="layui-form"  action="" lay-filter="edit">
    <div class="layui-form-item">
        <label class="layui-form-label">药物编号：</label>
        <div class="layui-input-inline">
            <input type="text" name="id" lay-verify="required" readonly="true" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">药品名：</label>
        <div class="layui-input-inline">
            <input type="text" name="name" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">剂型：</label>
        <div class="layui-input-inline">
            <input type="text" name="drug_type" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">制剂规格：</label>
        <div class="layui-input-inline">
            <input type="text" name="specification" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">制剂单位：</label>
        <div class="layui-input-inline">
            <input type="text" name="unit" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否限制药：</label>
        <div class="layui-input-inline">
            <select name="limit_status" id="limit_status">
                <option value="">请选择是否限制类药物</option>
                <option value="1">是</option>
                <option value="0">否</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">功效分类：</label>
        <div class="layui-input-inline">
            <input type="text" name="efficacy_classification" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">批发价：</label>
        <div class="layui-input-inline">
            <input type="text" name="wholesale_price" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">售价：</label>
        <div class="layui-input-inline">
            <input type="text" name="price" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库存量：</label>
        <div class="layui-input-inline">
            <input type="text" name="drug_count" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">生产厂家：</label>
        <div class="layui-input-inline">
            <input type="text" name="manufacturer" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">生产日期：</label>
        <div class="layui-input-inline">
            <input type="text" name="production_date" id="production_date" placeholder="yyyy-MM-dd"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">保质日期：</label>
        <div class="layui-input-inline">
            <input type="text" name="quality_date" id="quality_date" placeholder="yyyy-MM-dd"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">确认修改</button>
        </div>
    </div>
</form>
</body>
<script src="/static/js/system.js"></script>
<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/layui/layui.js"></script>
<script>
    //Demo
    layui.use(['form','layer'], function(){
        var form = layui.form, laydate = layui.laydate;
        laydate.render({
            elem: '#quality_date'
        });
        laydate.render({
            elem: '#production_date'
        });
        $.ajax({
            url:'/drug/findById',
            type:"post",
            dataType:"json",
            data:{"id":getQueryString("id")},
            success:function (da) {
                console.log(da)
                if (da.code == 200) {
                    form.val("edit", da.data);
                    form.val("edit", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                        "time": layui.util.toDateString(da.data.time, 'yyyy-MM-dd')
                    });
                } else {
                    parent.layer.msg("详情查询失败！");
                }
            }
        });
        //监听提交
        form.on('submit(formDemo)', function (data) {
            var data1 = form.val("edit");
            $.ajax({
                url: '/drug/update',
                type: "post",
                dataType: "json",
                data: data1,
                success: function (da) {
                    console.log(da)
                    if (da.code == 200) {
                        layer.alert("修改成功！", function () {
                            // window.parent.location.reload();//刷新父页面
                            // parent.layer.close(layer.index);//关闭弹出层
                            parent.layer.closeAll();
                        });
                    } else {
                        layer.msg("修改失败！");
                    }
                }
            });
            return false;
        });
    });
</script>
</html>
